package leetcode.editor.vip.Solition1650;

public class Solution1650 {
    class Node {
        int val;
        Node left;
        Node right;
        Node parent;
    }

    Node lowestCommonAncestor(Node p, Node q) {
        Node a = p, b = q;
        while (a != b) {
            if (a == null) a = q;
            else a = a.parent;

            if (b == null) b = p;
            else b = b.parent;

            // 不能放后面，因为可能只出现一个节点情况
//            a = a.parent;
//            b = b.parent;
        }

        return a;
    }
}
